﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace SimpleMailbox.WebAPI
{
	public class MailController : ApiController
	{
		private static List<MailMessage> messageList;

		static MailController()
		{
			messageList = new List<MailMessage>() 
			{ 
				new MailMessage { Id = 1, Body = "Body1", Title = "Title1" , DateReceived = DateTime.Now}
				, new MailMessage {Id = 2,  Body = "Body2", Title = "Title2", DateReceived = DateTime.Now.AddDays(-1)} 
			};

		}

		public List<MailMessage> Get()
		{
			return messageList;
		}

		public MailMessage Get(int msgId)
		{
			return messageList.FirstOrDefault(message=>message.Id == msgId);
		}

		[HttpPost]
		public string Post([FromBody]MailMessagePOST Message)
		{
			if (Message.Body != null)
				return "Message Sent!";
			else return "Message NOT Sent!";
		}
	}
}